﻿using System.Linq;
using Complaint.Models.Dtos;

namespace Complaint.Repositories
{
    public class PasswordQuestionRepository : BaseRepository<PasswordQuestion>, IRepository<PasswordQuestion>
    {
        #region Implementation of IRepository<PasswordQuestion>

        public void Create(PasswordQuestion dto)
        {
            ObjectContext.AddToPasswordQuestion(dto);
            Update(dto);
        }

        public IQueryable<PasswordQuestion> FindAll()
        {
            return ObjectContext.PasswordQuestion;
        }

        public PasswordQuestion FindById(int id)
        {
            return FindAll().FirstOrDefault(s => s.PasswordQuestionID == (short) id);
        }

        public IQueryable<PasswordQuestion> FindByName(string name)
        {
            return from passwordQuestion in FindAll()
                   where passwordQuestion.Question.Contains(name)
                   select passwordQuestion;
        }

        #endregion
    }
}